﻿using ABPLHQCS.Application;
using ABPLHQCS.FormItems;
using ABPLHQCS.Permissions;
using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace ABPLHQCS.FormInstances
{
    public class FormInstanceAppService: CrudAppService<
        FormInstance,
        FormInstanceDto,
        Guid,
        PagedAndSortedResultRequestDto,
        FormInstanceCreateAndUpdateDto
        >, IFormInstanceAppService
    {

        public FormInstanceAppService(IRepository<FormInstance, Guid> repository) : base(repository)
        {
            GetPolicyName = ABPLHQCSPermissions.FormInstances.Default;
            GetListPolicyName = ABPLHQCSPermissions.FormInstances.Default;
            CreatePolicyName = ABPLHQCSPermissions.FormInstances.Create;
            UpdatePolicyName = ABPLHQCSPermissions.FormInstances.Edit;
            DeletePolicyName = ABPLHQCSPermissions.FormInstances.Delete;
        }


        [AllowAnonymous]
        public override async Task<FormInstanceDto> CreateAsync(FormInstanceCreateAndUpdateDto input)
        {
            if (input.Id!=Guid.Empty)
            {
                var existFormInstance = await GetEntityByIdAsync(input.Id);
                if (existFormInstance != null)
                {
                    return await UpdateAsync(input.Id, input);
                }
            }

            return await base.CreateAsync(input);


          

        }

    }

 
}
